import http from '../../http'
import type { ApiResponse, PageResponse, ArticleListItemVO, ArticleDetailVO } from '@/types/api'

export interface SaveArticleDTO {
  title: string
  content?: string
  summary?: string
  coverImage?: string
  categoryId?: number
  status?: number
  tagIds?: number[]
}

export async function adminCreateArticle(payload: SaveArticleDTO) {
  const resp = await http.post<ApiResponse<{ id: number }>>('/articles', payload)
  return resp.data
}

export async function adminUpdateArticle(id: number, payload: SaveArticleDTO) {
  const resp = await http.put<ApiResponse<boolean>>(`/articles/${id}`, payload)
  return resp.data
}

export async function adminDeleteArticle(id: number) {
  const resp = await http.delete<ApiResponse<boolean>>(`/articles/${id}`)
  return resp.data
}

export async function adminPageArticles(params: { pageNo: number; pageSize: number; keyword?: string; status?: number }) {
  const resp = await http.get<ApiResponse<PageResponse<ArticleListItemVO>>>('/admin/articles', { params })
  return resp.data
}

export async function adminGetArticleDetail(id: number) {
  const resp = await http.get<ApiResponse<ArticleDetailVO>>(`/articles/${id}`)
  return resp.data
}


